package test.core.fun;

import hyl.core.run.IDo;
import hyl.core.run.IDoEach;
import hyl.core.run.IMark;

public class testsign {

}

class Mysign {
	//执行完成后回调
	Runnable finished = null;
	//信号灯数量
	int size = 1;
	//信号灯集合
	byte[] sign = null;
	public Mysign(Runnable 完成后调用) {
		sign = new byte[1];
		finished = 完成后调用;
	}

	public Mysign(int 信号灯数, Runnable 完成后调用) {
		if (信号灯数 > 0)
			size = 信号灯数;
		sign = new byte[size];
		finished = 完成后调用;
	}

	public void call(int index, IMark fun) {
		if (fun == null)
			return;
		if (fun.run()) {	
			sign[index] = 1;
			onfinish();
		}
	}

	public synchronized void setSize(int len) {	
		if (len > size) {
			byte[] sign2 = new byte[len];
			for (int i = 0; i < size; i++) {
				sign2[i] = sign[i];
			}
			sign = sign2;
			size = len;
		}	
	}

	public synchronized void onfinish() {
		for (int i = 0; i < size; i++) {
			if (sign[i] == 0)
				return;
		}
		if (finished == null)
			return;
		finished.run();
	}
}